import store from '@/store'
import { requst, loadingRequst } from './axios'
import qs from 'qs'

export function getUserInfo(user) {
    requst.get(`https://api.usuuu.com/qq/${user}`).then(res => {
        if (res.code == 200) {
            store.commit('userinfo', res.data)
            store.commit('loginMask', false)
            localStorage.setItem('user', user)
        }

    })
    releaselist(user)
}
export async function getlist() {
    const list = await homelist()
    setTimeout(() => {
        store.commit('homelist', list.data);
    }, 2000);
}

function homelist() {
    return loadingRequst.get('/api/home.php')
}

export function hongbaolist(id) {

    return requst.get(`/api/hongbao.php?id=${id}`)

}
export function deleteitem(id) {

    return requst.get(`/api/delete.php?id=${id}`)

}

export function getresults(data) {
    return requst.post('/api/results.php', qs.stringify(data, { arrayFormat: 'indices' }))
}

export function setlist(data) {
    return requst.post('/api/setlist.php', qs.stringify(data, { arrayFormat: 'indices' }))
}

function releaselist(user) {
    requst.get(`/api/userlist.php?user=${user}`).then(res => {
        let data = res.data
        if (res.code == '200') {
            store.commit('uodataUserlist', data);
        }
    })

}